package com.xm.servlet.reception_desk.login;


import com.xm.service.reception_desk.AccountInformationService;
import com.xm.service.reception_desk.AccountService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;


/**
 * 手机号注册
 * @author 康文程
 * @date 2023-12-25 上午 08:53
 */
@WebServlet("/phone/registration")
public class PhoneRegistration extends HttpServlet {
    private final AccountService service = new AccountService();
    private final AccountInformationService accountInformationService = new AccountInformationService();

    /**
     * 手机号注册
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)  {
        String phone = req.getParameter("phone");
        String password = req.getParameter("password");
        //新增账号表
        int id = service.addPhoneAccount(phone, password);
        //新增账号信息表
        resp.getWriter().println( accountInformationService.addAccountInformation(String.valueOf(UUID.randomUUID()), id));
    }
}
